package operations;

import agent.BoatStates;
import agent.State;

public class LoadGoat implements Operation{

	@Override
	public State exec(State n) {
		if (!validOperation(n))
			return null;
		State ret = n.dupe();
		
		if (ret.isBoatLeft() && ret.isGoatLeft())
			ret.setGoatLeft(false);
		if (ret.isBoatRight() && ret.isGoatRight())
			ret.setGoatRight(false);
			
		ret.setBoatPassanger(BoatStates.goat);
		
		return ret;
	}

	@Override
	public boolean validOperation(State n) {
		if (n.getBoatPassanger()!=BoatStates.empty)
			return false;
		if (n.isBoatLeft())
				if (!n.isGoatLeft())
					return false;
		if (n.isBoatRight())
			if (!n.isGoatRight())
				return false;
		return true;
	}

}
